import React, { Component } from 'react';
import {
    Button,
    View,
    Text,
} from 'react-native'

class HomeScreen extends Component {
    state={count:0};
    static navigationOptions= {
        title:'Home页',
    };

    componentWillMount() {                    //通过setParams将increase方法绑定到_increase
      this.props.navigation.setParams({ increase: this._increase });
    }
    _increase=()=>{                           //设置state.count+1
      this.setState(preState=>{return {count:preState.count+1}});
    };

    render() {
        datas = {
          increase:"a"
        }
        return (
            <View>
                <Button title='+1' onPress={() => {  this._increase(); }} />
                <Text>计数为：{this.state.count}</Text>
                <Button title='跳转到详情' onPress={()=>this.props.navigation.navigate('Detail',datas)} />
            </View>
        )
    }

}

export default HomeScreen;
